from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader, RequestContext
from app01.models import BookInfo


# Create your views here.

def index(request):
    return HttpResponse("欢迎使用")


def user_list(request):
    # 获取模板
    #template = loader.get_template('user_list.html')
    # 定义上线文
    # 2.定义上下文
    #context = {
     #   'h1': 'Hello world',
    #    'list': range(10)
   # }
    # return HttpResponse("用户列表")
    #return HttpResponse(template.render(context, request))
    booklist= BookInfo.objects.all()
    return render(request, 'user_list.html', {'booklist': booklist})


def user_add(request):
    return HttpResponse("用户添加")

def detail(request,bid):
    book = BookInfo.objects.get(id=int(bid))
    heros = book.heroinfo_set.all()
    return render(request, 'detail.html', {'book': book, 'heros': heros})
